using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bar : GunForEnemy
{
    public int bulletNum;
    public int directionNum;
    public float bulletAngle;
    protected override void Update()
    {
        //mousePos = GameObject.FindWithTag("Player").transform.position;
        if (father.GetComponent<FSM>() != null)
            mousePos = father.GetComponent<FSM>().parameter.target.position;
        if (father.GetComponent<FSM2>() != null)
            mousePos = father.GetComponent<FSM2>().parameter.target.position;
        direction = (mousePos - new Vector2(transform.position.x, transform.position.y)).normalized;
        Shoot();
    }
    protected override void fire()
    {
        timer = interval;
        anim.SetTrigger("shoot");
        float median = (bulletNum + 1) / 2;
        for (int i = 1; i <= bulletNum; i++)
        {
            for(int j = 0; j <= directionNum; j++)
            {
                GameObject bullet = ObjectPool.Instance.GetObject(bulletPrefab);
                bullet.transform.position = muzzlePos.position;
                Vector2 _direction = Quaternion.AngleAxis(j * 360 / directionNum + bulletAngle * (i - median), Vector3.forward) * direction;
                bullet.transform.right = _direction;
                bullet.GetComponent<bullet>().SetSpeed(_direction);
            }
        }
    }
}
